﻿using STHPMS1.Common.C_Entity;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.Common.C_Enum;
using STHPMS1.ICore;
using STHPMS1.ICore.I_Core;
using STHPMS1.ICore.I_UI;
using System;
using System.Collections;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace STHPMS1.Web.W_Controller
{
    [RoutePrefix("api/recommend")]
    public class Dr_RepaircostPage1Controller : STHPMS1.Web.W_Core.MyController
    {
        [Route("")]
        [Route("page/{page?}", Name = "GetrecommendByPage")]
        [Route("rows/{rows?}")]
        [Route("page/{page?}/rows/{rows?}")]
        public IHttpActionResult Get(int page = 1, int rows = 10)
        {
            int p = page;
            int s = rows;

            PagingInfo info = new PagingInfo();
            info.PageIndex = p > 0 ? p - 1 : 0;
            info.PageSize = s;
            info.TotalRecords = 0;

            var data = this.Scene.Bll.Dr_Decision_Tree.Get<Dr_Decision_Tree>(null, info).ToArray();
            if (data == null) return NotFound();
            var result = new { rows = data, total = info.TotalRecords };

            return Ok(result);
        }

        [Route("")]
        public HttpResponseMessage Post(Dr_Repaircost entity)
        {
            //this.Scene.Bll.Dr_Repaircost.Save(entity);

            var response = Request.CreateResponse(HttpStatusCode.Created);
            // Generate a link to the new book and set the Location header in the response.
            string uri = Url.Link("GetrepaircostByPage", new { page = 1 });
            response.Headers.Location = new Uri(uri);

            return response;
        }

        [Route("")]
        public void Delete(Dr_Decision_Tree entity)
        {
            this.Scene.Bll.Dr_Decision_Tree.Remove(entity);
        }

        /// <summary>
        /// 获取比选方案
        /// </summary>
        /// <param name="mainSegId"></param>
        /// <returns></returns>
        [Route("c_get")]
        public dynamic GetComparePlan(string proj_Id)
        {
            var data = this.Scene.Bll.Dr_Repaircost.GetComparePlan(proj_Id);

            return data;
        }

        /// <summary>
        /// 路面大中修分析期 费用保存
        /// </summary>
        /// <returns></returns>
        [Route("c_save")]
        public void PostAnalyCost(STHPMS1.Common.C_Entity.PageModel.ComparePlanModel data)
        {
            this.Scene.Bll.Dr_Repaircost.SaveAnalyCost(data);
        }

        /// <summary>
        /// 计算全寿命周期费用
        /// </summary>
        /// <param name="proj_Id"></param>
        [Route("c_cala")]
        public void PostCalacFullLifeCycleCost(string proj_Id)
        {
            this.Scene.Bll.Dr_Lifecyclecost.CalacFullLifeCycleCost(proj_Id);
        }

        /// <summary>
        /// 获取比选方案的初期建设费用
        /// </summary>
        /// <param name="proj_Id"></param>
        /// <param name="mainsegid"></param>
        /// <returns></returns>
        [Route("b_get")]
        public dynamic GetIniCost(string proj_Id,string mainsegid )
        {
            return this.Scene.Bll.Dr_Initialconstructioncost.GetIniCost(proj_Id, mainsegid);
        }

        /// <summary>
        /// 获取分析期维修策略及费用
        /// </summary>
        /// <param name="proj_Id"></param>
        /// <returns></returns>
        [Route("r_get")]
        public dynamic GetRepairCost(string proj_Id)
        {
            return this.Scene.Bll.Dr_Repaircost.GetRepairCost(proj_Id);
        }

        /// <summary>
        /// 获取分析期寿命周期费用
        /// </summary>
        /// <param name="proj_Id"></param>
        /// <returns></returns>
        [Route("l_get")]
        public dynamic GetCycleLifeCost(string proj_Id)
        {

            return this.Scene.Bll.Dr_Lifecyclecost.GetCycleLifeCost(proj_Id);
        }
    }

}